<template>
    <div class="sub-layout role-content">
        <div class="sub-sidebar">
            <div class="search-bar">
                <div class="search-box"></div>
                <permission class="add" permission-key="role:addRole">
                    <a @click="showEditLayer(0)">
                        <i class="icon i-plus"></i>
                    </a>
                </permission>
            </div>
            <div class="side-nav">
                <el-tree node-key="id" :props="roleDefaultProps" :data="roleList" @node-click="nodeClick"></el-tree>
            </div>
        </div>
        <div class="sub-main">
            <div class="content" v-if="currentData.name">
                <div class="section-info">
                    <span class="name">{{currentData.name}}</span>
                    <permission permission-key="role:editRole">
                        <button @click="showEditLayer(1)">修改</button>
                    </permission>
                    <permission permission-key="role:delRole">
                        <button class="btn-delete" @click="showDeleteLayer">删除</button>
                    </permission>
                    <permission permission-key="role:addRole">
                        <button @click="showEditLayer(2)">添加子角色</button>
                    </permission>
                </div>
                <div class="section section-table">
                    <div class="panel-title">
                        <span class="title">角色定义</span>
                    </div>
                    <div class="panel-content">
                        <el-tree ref="treeResource" show-checkbox default-expand-all check-strictly node-key="id" :data="treeRoleResource" :props="resourceDefaultProps"
                            :default-checked-keys="resourceDefaultCheckedId">
                        </el-tree>
                        <permission permission-key="role:editDiction">
                            <div class="form-btn">
                                <button @click="sumbitSave">保存</button>
                            </div>
                        </permission>
                    </div>
                </div>
            </div>
        </div>
        <!-- 编辑layer -->
        <layer :data="editLayerData" @on-cancel="closeEditLayer" @on-ok="editLayerConfirm">
            <div class="el-form">
                <div class="el-form-item is-required" :class="{'is-error':editLayerData.error}">
                    <label class="el-form-item__label" style="width: 100px;">角色名称</label>
                    <div class="el-form-item__content" style="margin-left: 112px;">
                        <div class="el-input">
                            <input autocomplete="off" type="text" validateevent="true" class="el-input__inner" placeholder="请输入角色名称" v-model="editLayerData.name"
                                @blur="layerInputBlur">
                        </div>
                        <div class="el-form-item__error" v-if="editLayerData.error">请输入角色名称</div>
                    </div>
                </div>
            </div>
        </layer>
        <!-- 删除layer  -->
        <layer :data="deleteLayerData" @on-ok="deleteLayerConfirm"></layer>
    </div>
</template>
<script>
    import roleMixin from './role'
    export default {
        name: 'role',
        mixins: [roleMixin]
    }
</script>